package com.sunlake.spring.main.common.enums.role;

import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

@Getter
public enum RoleEnum {
    USER("USER", "普通用户"),
    COUNSELOR("COUNSELOR", "顾问"),
    ADMIN("ADMIN", "管理员");

    private final String code;
    private final String description;

    RoleEnum(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @JsonValue
    public String getCode() {
        return code;
    }

    // 根据code获取枚举实例
    public static RoleEnum fromCode(String code) {
        for (RoleEnum role : values()) {
            if (role.code.equals(code)) {
                return role;
            }
        }
        return USER; // 默认返回普通用户
    }
}